import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:guochaoapp/common/widges/appbar.dart';
import 'package:guochaoapp/controller/mine/add_address_controller.dart';
import 'package:guochaoapp/model/address_entity.dart';
import 'package:guochaoapp/r.dart';

class GCAddAddressPage extends StatelessWidget {
  GCAddAddressController c = Get.put(GCAddAddressController());

  @override
  Widget build(BuildContext context) {

    if(Get.arguments[0] == "edit") {
      c.isEdit = true;
      AddressDataRecord model = Get.arguments[1];
      c.model = model;
      c.receiverPhone.value = model.receiverPhone;
      c.receiverName.value = model.receiverName;
      c.receiverAddr.value = model.receiverAddr;
    } else {
      c.isEdit = false;
      c.receiverPhone.value = "";
      c.receiverName.value = "";
      c.receiverAddr.value = "上海市静安区";
    }

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: GCAppBar(titleText: "收获地址"),
      body: _initSubviews(),
    );
  }

  GlobalKey<FormState> _formKey = GlobalKey<FormState>();

  FocusNode _onefocusNode = FocusNode();
  FocusNode _twofocusNode = FocusNode();

  _endEdit() {
    _onefocusNode.unfocus();
    _twofocusNode.unfocus();
  }

  _initSubviews() {
    return GestureDetector(
      onTap: _endEdit,
      child: Container(
        color: Colors.white,
        child: ListView(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.only(
                  left: 16, right: 23, top: 30, bottom: 50),
              child: Form(
                key: _formKey,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Container(
                      height: 40,
                      color: Colors.white,
                      child: Row(
                        children: <Widget>[
                          Container(
                              width: 65,
                              child: Text("收货人",
                                  style: TextStyle(
                                      fontSize: 16, color: Color(0xFF666666)))),
                          SizedBox(width: 12),
                          Expanded(
                            child: TextFormField(
                              initialValue: c.receiverName.value,
                              focusNode: _onefocusNode,
                              textInputAction: TextInputAction.next,
//                                      onFieldSubmitted: (v) => FocusScope.of(context).requestFocus(_passwdfocusNode),
                              onSaved: (value) => c.receiverName.value = value,
                              onChanged: (value) => c.receiverName.value = value,
                              decoration: InputDecoration(
                                contentPadding: EdgeInsets.only(left: 10),
                                hintText: "请输入收货人姓名",
                                hintStyle: TextStyle(
                                    fontSize: 13, color: Color(0xFFD8D8D8)),
                                enabledBorder: OutlineInputBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(4)),
                                    borderSide: BorderSide(
                                      color: Color(0xFFD8D8D8),
                                    )),
                                focusedBorder: OutlineInputBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(4)),
                                    borderSide:
                                        BorderSide(color: Color(0xFFD8D8D8))),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 20),
                    Container(
                      height: 40,
                      color: Colors.white,
                      child: Row(
                        children: <Widget>[
                          Container(
                              width: 65,
                              child: Text("手机号码",
                                  style: TextStyle(
                                      fontSize: 16, color: Color(0xFF666666)))),
                          SizedBox(width: 12),
                          Expanded(
                            child: TextFormField(
                              initialValue: c.receiverPhone.value,
                              focusNode: _twofocusNode,
                              textInputAction: TextInputAction.next,
//                                      onFieldSubmitted: (v) => FocusScope.of(context).requestFocus(_passwdfocusNode),
                              onSaved: (value) => c.receiverPhone.value = value,
                              onChanged: (value) => c.receiverPhone.value = value,
                              decoration: InputDecoration(
                                contentPadding: EdgeInsets.only(left: 10),
                                hintText: "请输入收货人手机号码",
                                hintStyle: TextStyle(
                                    fontSize: 13, color: Color(0xFFD8D8D8)),
                                enabledBorder: OutlineInputBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(4)),
                                    borderSide: BorderSide(
                                      color: Color(0xFFD8D8D8),
                                    )),
                                focusedBorder: OutlineInputBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(4)),
                                    borderSide:
                                        BorderSide(color: Color(0xFFD8D8D8))),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 24),
                    Container(color: Color(0xFFE3E1E4), height: 1),
                    Container(
                        height: 63,
                        child: Row(children: [
                          Container(
                              width: 65,
                              child: Text("省市地址",
                                  style: TextStyle(
                                      fontSize: 16, color: Color(0xFF666666)))),
                          SizedBox(width: 12),
                          Expanded(
                            child: Text(c.receiverAddr.value,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    color: Theme.of(Get.context).primaryColor,
                                    fontSize: 16)),
                          ),
                          SizedBox(width: 3),
                          Image.asset(R.assetsIconHomeBarcket,
                              width: 22, height: 22),
                        ])),
                    Container(color: Color(0xFFE3E1E4), height: 1),
                    Container(
                        padding: EdgeInsets.only(top: 17, bottom: 17),
                        height: 176,
                        child: Row(children: [
                          Container(
                              width: 65,
                              child: Text("详细地址",
                                  style: TextStyle(
                                      fontSize: 16, color: Color(0xFF666666)))),
                          SizedBox(width: 12),
                          Expanded(
                              child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xFFF4F4F4),
                              border: Border.all(
                                  color: Color(0xFFD8D8D8), width: 1),
                            ),
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  left: 9, right: 9, top: 7, bottom: 7),
                              child: Column(
                                children: [
                                  Container(
                                    width: double.infinity,
                                    child: Text(
                                      c.receiverAddr.value,
                                    textAlign: TextAlign.start,
                                    style: TextStyle(
                                      fontSize: 16, color: Color(0xFF666666)),
                                  ),
                                  ),
                                  SizedBox(),
                                ],
                              ),
                            ),
                          )),
                        ])),
                    Container(color: Color(0xFFE3E1E4), height: 1),
                    SizedBox(height: 8),
                    Text("*如您的送货地址未列入地图选点，可选择相近地址，这并不会影响您的货物送达",
                        style:
                            TextStyle(color: Color(0xFFBEBEBF), fontSize: 10)),
                    SizedBox(height: 56),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Container(
                          width: 248,
                          height: 37,
                          child: RaisedButton(
                              color: Theme.of(Get.context).primaryColor,
                              onPressed: c.submitTap,
                              child: Text(
                                "添加",
                                style: TextStyle(color: Colors.white),
                              )),
                        )
                      ],
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
